package cn.jhc.booklist;

import android.app.ListFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

/**
 * Created by luyanfei on 16-2-26.
 */
public class BookListFragment extends ListFragment {
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        String[] bookTitles = getResources().getStringArray(R.array.bookTitles);
        ArrayAdapter<String> bookTitlesAdapter =
                new ArrayAdapter<String>(getActivity(),
                        android.R.layout.simple_list_item_1, bookTitles);
        setListAdapter(bookTitlesAdapter);
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        OnSelectedBookChangeListener listener = (OnSelectedBookChangeListener) getActivity();
        listener.onSelectedBookChanged(position);
    }
}
